home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / exctsccr.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  188 lines

  1. /*************************************************************************************
  2.  
  3. Emulation of the Alpha 8302 microcontroller.
  4.  
  5. All tables built manually from the analisis of the bootleg set.
  6.  
  7. The main purpose of the MCU is to control the program flow.
  8. This tables are actually subroutine addresses, wich get pushed
  9. onto the stack one after the other. Basically then the program
  10. runs and when it returns on one of these subroutines, it expects
  11. to land on the proper 'next' subroutine.
  12.  
  13. Ernesto Corvi - 10/30/98
  14.  
  15. *************************************************************************************/
  16.  
  17. #include "driver.h"
  18.  
  19.  
  20. #define MCU_KEY_TABLE_SIZE 16
  21.  
  22. /* These are global */
  23. unsigned char *exctsccr_mcu_ram;
  24. WRITE_HANDLER( exctsccr_mcu_w );
  25. WRITE_HANDLER( exctsccr_mcu_control_w );
  26.  
  27. /* Local stuff */
  28. static int mcu_code_latch;
  29.  
  30. /* input = 0x6009 - data = 0x6170 */
  31. static unsigned char mcu_table1[MCU_KEY_TABLE_SIZE] = {
  32.     0x23, 0x05, 0xfb, 0x07, 0x4d, 0x3b,    0x7d, 0x03,
  33.     0x9a, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  34. };
  35.  
  36. /* input = 0x600d - data = 0x61f0 */
  37. static unsigned char mcu_table2[MCU_KEY_TABLE_SIZE] = {
  38.     0x75, 0x25, 0x4b, 0x10, 0xa6, 0x06,    0x9a, 0x02,
  39.     0x04, 0x11, 0x09, 0x09,    0x2a, 0x10, 0x3a, 0x10
  40. };
  41.  
  42. /* input = ?????? - data = 0x6300 */
  43. static unsigned char mcu_table3[MCU_KEY_TABLE_SIZE*4] = {
  44.     0xba, 0x26,    0x53, 0x0d, 0x01, 0x24, 0x1d, 0x15,
  45.     0xd0, 0x1d, 0x35, 0x1f, 0x32, 0x22,    0xa0, 0x2c,
  46.  
  47.     0x5e, 0x2e, 0x92, 0x2e,    0xf9, 0x2e, 0x43, 0x2f,
  48.     0x59, 0x2f,    0x6f, 0x2f, 0xd1, 0x38, 0xd8, 0x3e,
  49.  
  50.     0x9e, 0x0d, 0x4c, 0x47, 0x1f, 0x1f,    0x5a, 0x1f,
  51.     0xbe, 0x22, 0xa2, 0x23,    0x33, 0x35, 0x69, 0x34,
  52.  
  53.     0x7c, 0x3a,    0x00, 0x00, 0xdc, 0x44, 0x78, 0x0b,
  54.     0x65, 0x0d, 0xc4, 0xb2, 0xc4, 0xb2, 0xc4, 0xb2
  55. };
  56.  
  57. /* input = 0x6007 - data = 0x629b */
  58. static unsigned char mcu_table4[MCU_KEY_TABLE_SIZE] = {
  59.     0xc5, 0x24, 0xc5, 0x24, 0x27, 0x3f,    0xd0, 0x07,
  60.     0x07, 0x0b, 0xd8, 0x02, 0x9a, 0x08, 0x00, 0x00
  61. };
  62.  
  63. /* input = 0x6007 - data = 0x629b */
  64. static unsigned char mcu_table5[MCU_KEY_TABLE_SIZE] = {
  65.     0x54, 0x43, 0xd0, 0x07, 0xd8, 0x02, 0x9a, 0x08,
  66.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  67. };
  68.  
  69. /* input = 0x6007 - data = 0x629b */
  70. static unsigned char mcu_table6[MCU_KEY_TABLE_SIZE] = {
  71.     0x2b, 0x03, 0xd0, 0x07, 0xd8, 0x02, 0x9a, 0x08,
  72.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  73. };
  74.  
  75. /* input = 0x6007 - data = 0x629b */
  76. static unsigned char mcu_table7[MCU_KEY_TABLE_SIZE] = {
  77.     0xfa, 0x0e, 0x9a, 0x08, 0x00, 0x00, 0x00, 0x00,
  78.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  79. };
  80.  
  81. /* input = 0x6011 - data = 0x607f */
  82. static unsigned char mcu_table8[MCU_KEY_TABLE_SIZE*2] = {
  83.     0x0b, 0x78, 0x47, 0x04, 0x36, 0x18, 0x23, 0xf1,
  84.     0x10, 0xee, 0x16, 0x04, 0x11, 0x94, 0x16, 0xdd,
  85.  
  86.     0x13, 0x4e, 0x06, 0xa6, 0x13, 0x12, 0x08, 0x9a,
  87.     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  88. };
  89.  
  90. static void mcu_sort_list( unsigned char *src, unsigned char *dst ) {
  91.     int i;
  92.  
  93.     for ( i = 0; i < 0x20; i++ ) {
  94.         int where = src[i];
  95.  
  96.         if ( where < 0x20 ) {
  97.             int offs = ( i << 1 );
  98.  
  99.             where <<= 1;
  100.             dst[where] = mcu_table3[offs];
  101.             dst[where+1] = mcu_table3[offs+1];
  102.         }
  103.     }
  104. }
  105.  
  106. WRITE_HANDLER( exctsccr_mcu_control_w ) {
  107.  
  108.     if ( data == 0xff ) { /* goes around the mcu checks */
  109.         exctsccr_mcu_ram[0x0003] = 0x01; /* mcu state = running */
  110.  
  111.         exctsccr_mcu_ram[0x0005] = 0x08;
  112.         exctsccr_mcu_ram[0x0380] = 0xf1;
  113.         exctsccr_mcu_ram[0x0381] = 0x01;
  114.         exctsccr_mcu_ram[0x02f8] = 0x1f; /* Selects song to play during gameplay */
  115.  
  116.         exctsccr_mcu_ram[0x0009] = 0x08;
  117.         memcpy( &exctsccr_mcu_ram[0x0170], mcu_table1, MCU_KEY_TABLE_SIZE );
  118.  
  119.         if ( exctsccr_mcu_ram[0x000d] == 0x01 ) {
  120.             exctsccr_mcu_ram[0x000d] = 0x08;
  121.  
  122.             memcpy( &exctsccr_mcu_ram[0x01f0], mcu_table2, MCU_KEY_TABLE_SIZE );
  123.         }
  124.  
  125.         mcu_sort_list( &exctsccr_mcu_ram[0x03e0], &exctsccr_mcu_ram[0x0300] );
  126.  
  127.         exctsccr_mcu_ram[0x02fb] = 0x7e;
  128.         exctsccr_mcu_ram[0x02fd] = 0x7e;
  129.  
  130.         if ( mcu_code_latch ) {
  131.             exctsccr_mcu_ram[0x02f9] = 0x7f;
  132.             exctsccr_mcu_ram[0x02fa] = 0x0d;
  133.             exctsccr_mcu_ram[0x02fc] = 0x05;
  134.             exctsccr_mcu_ram[0x02fe] = 0x01;
  135.         } else {
  136.             exctsccr_mcu_ram[0x02f9] = 0x81;
  137.             exctsccr_mcu_ram[0x02fa] = 0x2d;
  138.             exctsccr_mcu_ram[0x02fc] = 0x25;
  139.             exctsccr_mcu_ram[0x02fe] = 0x09;
  140.         }
  141.  
  142.         if ( exctsccr_mcu_ram[0x000f] == 0x02 ) {
  143.             exctsccr_mcu_ram[0x000f] = 0x08;
  144.             exctsccr_mcu_ram[0x02f6] = 0xd6;
  145.             exctsccr_mcu_ram[0x02f7] = 0x39;
  146.         }
  147.  
  148.         if ( exctsccr_mcu_ram[0x0007] == 0x02 ) {
  149.             exctsccr_mcu_ram[0x0007] = 0x08;
  150.  
  151.             if ( exctsccr_mcu_ram[0x0204] > 3 )
  152.                 exctsccr_mcu_ram[0x0204] = 0;
  153.  
  154.             switch( exctsccr_mcu_ram[0x0204] ) {
  155.                 case 0x00:
  156.                     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table4, MCU_KEY_TABLE_SIZE );
  157.                 break;
  158.  
  159.                 case 0x01:
  160.                     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table5, MCU_KEY_TABLE_SIZE );
  161.                 break;
  162.  
  163.                 case 0x02:
  164.                     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table6, MCU_KEY_TABLE_SIZE );
  165.                 break;
  166.  
  167.                 case 0x03:
  168.                     memcpy( &exctsccr_mcu_ram[0x029b], mcu_table7, MCU_KEY_TABLE_SIZE );
  169.                 break;
  170.             }
  171.  
  172.             if ( exctsccr_mcu_ram[0x0204] != 3 )
  173.                 exctsccr_mcu_ram[0x0204]++;
  174.         }
  175.  
  176.         exctsccr_mcu_ram[0x0011] = 0x08;
  177.         memcpy( &exctsccr_mcu_ram[0x007f], mcu_table8, MCU_KEY_TABLE_SIZE*2 );
  178.     }
  179. }
  180.  
  181. WRITE_HANDLER( exctsccr_mcu_w ) {
  182.  
  183.     if ( offset == 0x02f9 )
  184.         mcu_code_latch = data;
  185.  
  186.     exctsccr_mcu_ram[offset] = data;
  187. }
  188.